From 0a64e72ee79e39ae1964dcbb95a5f7989967516f Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Fri, 17 Feb 2006 16:29:24 +0100 Subject: [PATCH] Fix HVM MSR save/restore. Signed-off-by: Keir Fraser Signed-off-by: Yunhong Jiang Signed-off-by: Xin Li --- xen/arch/x86/domain.c | 16 +++++++--------- xen/arch/x86/hvm/hvm.c | 1 - xen/arch/x86/hvm/svm/svm.c | 5 +---- xen/arch/x86/hvm/vmx/vmx.c | 5 +---- xen/include/asm-x86/hvm/hvm.h | 6 +++--- xen/include/asm-x86/hvm/support.h | 1 - 6 files changed, 12 insertions(+), 22 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 1bea8813ed..5e038cebf3 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -435,8 +435,6 @@ int arch_set_info_guest( if ( !hvm_initialize_guest_resources(v) ) return -EINVAL; - - hvm_switch_on = 1; } update_pagetables(v); @@ -685,6 +683,8 @@ static void __context_switch(void) CTXT_SWITCH_STACK_BYTES); unlazy_fpu(p); save_segments(p); + if ( HVM_DOMAIN(p) ) + hvm_load_msrs(); } if ( !is_idle_vcpu(n) ) @@ -710,6 +710,10 @@ static void __context_switch(void) set_int80_direct_trap(n); switch_kernel_stack(n, cpu); } + else + { + hvm_restore_msrs(next); + } } if ( p->domain != n->domain ) @@ -765,16 +769,10 @@ void context_switch(struct vcpu *prev, struct vcpu *next) /* Re-enable interrupts before restoring state which may fault. */ local_irq_enable(); - if ( HVM_DOMAIN(next) ) - { - hvm_restore_msrs(next); - } - else + if ( !HVM_DOMAIN(next) ) { load_LDT(next); load_segments(next); - if ( HVM_DOMAIN(next) ) - hvm_load_msrs(next); } } diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 1a0ec644c1..bbe3af8ea6 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -46,7 +46,6 @@ #include int hvm_enabled = 0; -int hvm_switch_on = 0; unsigned int opt_hvm_debug_level = 0; integer_param("hvm_debug", opt_hvm_debug_level); diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 4aa3b89be3..d4af058c65 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -251,14 +251,11 @@ void svm_save_segments(struct vcpu *v) * are not modified once set for generic domains, we don't save them, * but simply reset them to the values set at percpu_traps_init(). */ -void svm_load_msrs(struct vcpu *n) +void svm_load_msrs(void) { struct svm_msr_state *host_state = &percpu_msr[smp_processor_id()]; int i; - if ( !hvm_switch_on ) - return; - while ( host_state->flags ) { i = find_first_set_bit(host_state->flags); diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index c9f3171aa7..25a76348ec 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -124,14 +124,11 @@ void vmx_save_segments(struct vcpu *v) * are not modified once set for generic domains, we don't save them, * but simply reset them to the values set at percpu_traps_init(). */ -void vmx_load_msrs(struct vcpu *n) +void vmx_load_msrs(void) { struct vmx_msr_state *host_state = &percpu_msr[smp_processor_id()]; int i; - if ( !hvm_switch_on ) - return; - while ( host_state->flags ) { i = find_first_set_bit(host_state->flags); diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h index 9288e465d3..c4386e5267 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -50,7 +50,7 @@ struct hvm_function_table { void (*load_cpu_guest_regs)(struct vcpu *v, struct cpu_user_regs *r); #ifdef __x86_64__ void (*save_segments)(struct vcpu *v); - void (*load_msrs)(struct vcpu *v); + void (*load_msrs)(void); void (*restore_msrs)(struct vcpu *v); #endif void (*store_cpu_guest_ctrl_regs)(struct vcpu *v, unsigned long crs[8]); @@ -116,10 +116,10 @@ hvm_save_segments(struct vcpu *v) } static inline void -hvm_load_msrs(struct vcpu *v) +hvm_load_msrs(void) { if (hvm_funcs.load_msrs) - hvm_funcs.load_msrs(v); + hvm_funcs.load_msrs(); } static inline void diff --git a/xen/include/asm-x86/hvm/support.h b/xen/include/asm-x86/hvm/support.h index 07dac5f52e..3507e75024 100644 --- a/xen/include/asm-x86/hvm/support.h +++ b/xen/include/asm-x86/hvm/support.h @@ -133,7 +133,6 @@ extern unsigned int opt_hvm_debug_level; } while (0) extern int hvm_enabled; -extern int hvm_switch_on; enum { HVM_COPY_IN = 0, HVM_COPY_OUT }; extern int hvm_copy(void *buf, unsigned long vaddr, int size, int dir); -- 2.30.2